package com.chengyu.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.chengyu.core.annotation.LogControllerAnnotation;
import com.chengyu.core.domain.enums.GoodsEnums;
import com.chengyu.core.domain.enums.OrderEnums;
import com.chengyu.core.domain.form.GoodsSearchForm;
import com.chengyu.core.domain.form.OrderCommentSearchForm;
import com.chengyu.core.domain.form.OrderGroupSearchForm;
import com.chengyu.core.domain.result.OrderCommentResult;
import com.chengyu.core.entity.CommonPage;
import com.chengyu.core.enums.MethodType;
import com.chengyu.core.model.*;
import com.chengyu.core.request.GoodsBrandRequest;
import com.chengyu.core.request.PageParamRequest;
import com.chengyu.core.response.GoodsBrandListResponse;
import com.chengyu.core.response.GoodsBrandResponse;
import com.chengyu.core.result.CommonResult;
import com.chengyu.core.service.goods.GoodsBrandService;
import com.chengyu.core.service.goods.GoodsParamsService;
import com.chengyu.core.service.goods.GoodsService;
import com.chengyu.core.service.member.MemberCollectGoodsService;
import com.chengyu.core.service.member.MemberCollectShopService;
import com.chengyu.core.service.member.MemberViewGoodsService;
import com.chengyu.core.service.order.OrderCommentService;
import com.chengyu.core.service.order.OrderGroupService;
import com.chengyu.core.service.shop.ShopCouponService;
import com.chengyu.core.service.shop.ShopFreightService;
import com.chengyu.core.service.shop.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "品牌")
@Controller
@RequestMapping("/brand")
public class BrandController extends UserBaseController {

	@Autowired
	private GoodsService goodsService;
	@Autowired
	private ShopService shopService;
	@Autowired
	private MemberViewGoodsService memberViewGoodsService;
	@Autowired
	private GoodsParamsService goodsParamsService;
	@Autowired
	private MemberCollectGoodsService memberCollectGoodsService;
	@Autowired
	private MemberCollectShopService memberCollectShopService;
	@Autowired
	private ShopFreightService shopFreightService;
	@Autowired
	private ShopCouponService shopCouponService;
	@Autowired
	private OrderCommentService orderCommentService;
	@Autowired
	private OrderGroupService orderGroupService;


	@Autowired
	private GoodsBrandService goodsBrandService;

	//@PreAuthorize("hasAuthority('platform:product:brand:list')")
	@ApiOperation(value = "品牌分页列表")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public com.chengyu.core.result.CommonResult<List<GoodsBrandResponse>> getList(@Validated PageParamRequest pageParamRequest) {

		List<GoodsBrandResponse> goodsBrandResponse =  goodsBrandService.getCacheAllList();



		return com.chengyu.core.result.CommonResult.success(goodsBrandResponse);
	}

//	//@PreAuthorize("hasAuthority('platform:product:brand:list')")
//	@ApiOperation(value = "品牌分页列表")
//	@RequestMapping(value = "/list", method = RequestMethod.GET)
//	@ResponseBody
//	public com.chengyu.core.result.CommonResult<CommonPage<GoodsBrandListResponse>> getList(@Validated PageParamRequest pageParamRequest) {
//		return com.chengyu.core.result.CommonResult.success(CommonPage.restPage(goodsBrandService.getAdminPage(pageParamRequest)));
//	}

//	, Integer page, Integer pageSize
//	@ApiOperation(value = "分页列表")
//	@RequestMapping(value = "/list", method = RequestMethod.GET)
//	@ResponseBody
//	@ApiImplicitParams({
////            @ApiImplicitParam(name = "cid", value = "分类id", dataType = "int"),
//			@ApiImplicitParam(name = "type", value = "类型", dataType = "int"),
//			@ApiImplicitParam(name = "title", value = "标题", dataType = "string"),
////            @ApiImplicitParam(name = "author", value = "作者", dataType = "string")
//	})
//	public com.chengyu.core.entity.CommonResult<CommonPage<Assist>> getList(@Validated Assist request, @Validated PageParamRequest pageParamRequest) {
//		return com.chengyu.core.entity.CommonResult.success(CommonPage.restPage(assistService.getList(request, pageParamRequest)));
//	}


//    @LogControllerAnnotation(intoDB = true, methodType = MethodType.ADD, description = "新增品牌")
//    //@PreAuthorize("hasAuthority('platform:product:brand:add')")
//    @ApiOperation(value = "新增品牌")
//    @RequestMapping(value = "/add", method = RequestMethod.POST)
//    public CommonResult<String> add(@Validated GoodsBrandRequest request) {
//
//        return CommonResult.failed();
//    }

	@LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "修改品牌")
	//@PreAuthorize("hasAuthority('platform:product:brand:update')")
	@ApiOperation(value = "修改品牌")
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public com.chengyu.core.result.CommonResult<String> update(@Validated GoodsBrandRequest request) {

		if(request.getId() == null){
			if (goodsBrandService.add(request)) {
				return com.chengyu.core.result.CommonResult.success();
			}
		}else {
			if (goodsBrandService.edit(request)) {
				return com.chengyu.core.result.CommonResult.success();
			}
		}

		return com.chengyu.core.result.CommonResult.failed();
	}



	@LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "删除品牌")
	//@PreAuthorize("hasAuthority('platform:product:brand:delete')")
	@ApiOperation(value = "删除品牌")
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
	public com.chengyu.core.result.CommonResult<String> delete(@PathVariable(value = "id") Integer id) {
		if (goodsBrandService.delete(id)) {
			return com.chengyu.core.result.CommonResult.success();
		}
		return com.chengyu.core.result.CommonResult.failed();
	}



	@LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "修改品牌显示状态")
	//@PreAuthorize("hasAuthority('platform:product:brand:show:status')")
	@ApiOperation(value = "修改品牌显示状态")
	@RequestMapping(value = "/update/show/{id}", method = RequestMethod.POST)
	public com.chengyu.core.result.CommonResult<Object> updateShowStatus(@PathVariable(value = "id") Integer id) {
		if (goodsBrandService.updateShowStatus(id)) {
			return com.chengyu.core.result.CommonResult.success("修改成功");
		}
		return com.chengyu.core.result.CommonResult.failed("修改失败");
	}

	//@PreAuthorize("hasAuthority('platform:product:brand:cache:list')")
	@ApiOperation(value = "品牌缓存列表(全部)")
	@RequestMapping(value = "/cache/list", method = RequestMethod.GET)
	public com.chengyu.core.result.CommonResult<List<GoodsBrandResponse>> getCacheAllList() {
		return CommonResult.success(goodsBrandService.getCacheAllList());
	}
}
